home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / basic1 / pro9 / fed.doc < prev    next >
Text File  |  1987-07-31  |  18KB  |  360 lines

  1.  
  2.                                 Field Editor
  3.                             Keyboard Input Handler
  4.  
  5.                              (C) InfoSoft, 1987
  6.  
  7.  
  8.           I.       Introduction
  9.  
  10.         The care and use of FED can be a tad involved so it is documented
  11.      separate from the rest of GIZLIB.  This does not mean that it can or
  12.      may be distributed seperately from the rest of GIZLIB or FED.DOC.
  13.  
  14.         There are several (indeed many!) text input handlers around.  I
  15.      know, because I have, or have looked at many of them.  Many of them
  16.      require significant editing to work, or they are not modular, or they
  17.      require the event trapping switch, or they were inadeqaute in
  18.      functionality.  This is not to imply that FED is without its own
  19.      failings, but overall, it is very flexible.
  20.  
  21.           FED, which originally stood for Field EDitor, is modular.  It can
  22.      be called from the main code of another program very easily.
  23.  
  24.           As is, FED is very flexible in most every aspect.  You can change
  25.      most all of the operating parameters with the change of a flag or
  26.      two.
  27.  
  28.           Finally, FED does not require the use of any event trapping
  29.      switch, it identifies extended key codes on its own, like most all good
  30.      text input editors.
  31.  
  32.  
  33.  
  34.           II.          FED Files
  35.  
  36.        The key FED files are:
  37.      FED-DEMO.BAS  - The demo
  38.      EMP.DAT       - A random file of 7 or so records for the demo
  39.      CHGFLD.SUB    - The FCODE handler from FED-DEMO that can be easily
  40.                      modified for use in your program.
  41.      FED.OBJ       - The BRUN30 object file.  Since I find FED very useful
  42.                      and use it very often I have included the FED object
  43.                      code to allow you to include it in other (BUILDLIB)
  44.                      user libraries.  This object code will not successfully
  45.                      run if linked to object modules compiled via the /o,
  46.                      or BCOM30 option.
  47.  
  48.  
  49.         The demo is a pretty simple random file allowing you to edit the
  50.      various records in the file.  It is especially easy to use after
  51.      reviewing this documentation.  You are encouraged to read this
  52.      first so that as FED-DEMO executes, you can notice some of the key
  53.      features.
  54.  
  55.  
  56.  
  57.  
  58.         III.           FED Parameters, Syntax
  59.  
  60.           FED uses several switches and 3 arguments to control the flow
  61.      and text input.  The formal or direct parameters are:
  62.  
  63.      TEXT$ - The original or old text string to edit.
  64.      FSIZ  - An integer telling FED the maximum length allowed for the
  65.              TEXT$, the current text to be edited.
  66.      FCODE - The exit code returned by FED to tell you HOW they completed
  67.              that field or what key was pressed upon exitting FED.
  68.  
  69.           You should understand that you can actually use any names that
  70.      suit you in a call to a SUB...STATIC / END SUB subroutine.  That is,
  71.      you could use ED$ instead of TEXT$, or T$, or whatever you want.  FED
  72.      will operate just as expected, as long as you pass them in the right
  73.      order.  The correct syntax:
  74.  
  75.      CALL fed(text$, fsiz%, fcode%)
  76.  
  77.           The importance of FSIZ is that FED will not allow input after that
  78.      maximum size is reached, and maybe beep (bleep actually).  FED does not
  79.      change FSIZ on the return, so be sure to reset it for each successive
  80.      call.
  81.  
  82.  
  83.  
  84.  
  85.           IV.        Incorporating FED to your code
  86.  
  87.         There are a few simple things to do to get FED running in your
  88.      program:
  89.  
  90.         FED works off of 3 formal arguments (covered above) and several
  91.      COMMON parameters shared with the main, calling program.  This
  92.      allows you to share some parameters with FED very easily such as
  93.      Foreground Color, upper casing etc.
  94.  
  95.         The actual use and meaning of these common parameters are covered
  96.      later, here we are explaining how to set up for FED to work in your
  97.      program.  This is done by simply including the following line in the
  98.      beginning of your main code:
  99.  
  100.    COMMON /fedvars/ fg%, bg%, fgd%, bgd%, bleep%, edt%, nums%, num$, ucase%
  101.  
  102.         The meaning and use of the variables will be covered later, but in
  103.      setting up FED for use, it is important that you list them EXACTLY as
  104.      shown, ie in the order shown, WITH the type declarations.  The first
  105.      four are foreground and background colors and the rest are listed
  106.      alphabetically.
  107.  
  108.  
  109.  
  110.         Note that such COMMON statements must appear in your code BEFORE
  111.      any executable statements.  If you are not familar with the use of
  112.      COMMON it is suggested that you review pp 228-232 of the QB manual.
  113.      Also refer to the FED-DEMO source for proper set up.  In implementing
  114.      the FED variables, we have opted to make several of them COMMON to
  115.      allow FED to read and literally share the value of these varibles
  116.      with your main program and at the same time, keeps you from having to
  117.      pass all of them as formal arguments to FED. That is, intead of:
  118.  
  119.      CALL fed(t$,fsiz,fcode, fg,bg, fgd,bgd, bleep, edt, nums,num$, ucase)
  120.      all we do is:
  121.      CALL fed(t$, fsiz, fcode)
  122.  
  123.         The use of a blockname (/fedvars/) prevents FED from interfering
  124.      with other COMMON or COMMON SHARED variables, more precisely, it allows
  125.      the USE of additional COMMON or COMMMON SHARED variables.  To name
  126.      additional variables as COMMON declare them like this:
  127.  
  128.      DEFINT a-z
  129.      COMMON /fedvars/ fg%, bg%, fgd%, bgd%, _
  130.               bleep, edt%, nums%, num$, ucase%        ' FED block defined
  131.  
  132.      COMMON SHARED /newblock/ arg1, arg2, arg3        ' different block
  133.  
  134.      COMMON SHARED  a,_                               ' "blank" block of
  135.                     b,_                               '   COMMON variables
  136.                     c,_
  137.                     z
  138.  
  139.         Note that /fedvars/ need not carry the SHARED attribute, but the use
  140.      of a blockname allows FED to share those variables that it needs and
  141.      ONLY those, ie a SIZE error is not encountered if you use other COMMON
  142.      variables.  This allows for maximum flexibility.  Since you might only
  143.      set many of the /fedvars/ such as fg, bg, fgd, bgd, and bleep once,
  144.      they can be ignored after they are set.  Only edt, a more or less
  145.      auxillary flag is altered by FED.  The only restriction in this is
  146.      that unlike the formal arguments passed in the parentheses, the
  147.      COMMON /fedvars/ variabls _MUST_ use the variable names shown.  That
  148.      is, while t$ can be changed to text$ or fcode can be used as
  149.      fed.return.code as you please, fg must be referenced as fg, fgd as fgd,
  150.      edt as edt, ucase as ucase etc etc.
  151.  
  152.  
  153.  
  154.           V.         Internal Editting Keys
  155.  
  156.           Internally, FED does several things to provide a professional
  157.      "look" to its operation.  First, lets look at the editing fiunctions
  158.      and keys recognized:
  159.  
  160.      HOME     Places cursor at start of text or field.
  161.      END      Places cursor at first blank at end of the text.
  162.  
  163.  
  164.      Ctrl - End   Clear line from cursor to end of line.
  165.      Ctrl - X     Clear all text from current field.
  166.      Ctrl - U     Undoes current edit.  This does not restore the text to
  167.                   it's form in a disk text file, but restores the text to
  168.                   the form it was UPON ENTRY TO FED.  It cannot know what
  169.                   the text was or what form it was in PRIOR to the CALL.
  170.  
  171.  
  172.  
  173.      Arrow Keys    Move one character Right or Left.  FED will not allow the
  174.                    user to Cursor right into the hatched area if that
  175.                    means that more than 1 space trails the text.  That is,
  176.                    via the the right arrow, it will not allow more than 2
  177.                    consecutive spaces, as in "J. DOE  " or "J Q  Public".
  178.                    This can be achieved via the insert key however.
  179.  
  180.  
  181.      Ctrl Arrow Keys   Moves one word right or left
  182.  
  183.  
  184.      Ins     Insert works as expected, allowing text to be inserted at the
  185.              cursor, and changes the cursor to a block.  The Insert state
  186.              is toggled off upon exiting FED or "finishing" the field or
  187.              text.
  188.  
  189.  
  190.      Del     As expected, deletes characters to the right of the cursor.
  191.  
  192.  
  193.        No key state flags (such as a [ INS ] or [ Caps ] indicator) are
  194.      put to the screen.  This was viewed as intrusive in that where FED
  195.      places the flag could be an unacceptable location in some applications,
  196.      and it seemed to not be in the interest of speed, to be painting and
  197.      repainting such indicators.
  198.  
  199.  
  200.  
  201.  
  202.           VI.          FED Return Codes - FCODE
  203.  
  204.           This is the half of the meat of the program (The other half is
  205.      internal).  FCODE return to you a value dependant on what key is
  206.      pressed to complete the editing of the text.
  207.  
  208.           Needless to say, FED has undergown several forms and formats since
  209.      I first started work on it.  The object of most changes has been to
  210.      make the FCODEs more intuitive.  The current state may not seem to be
  211.      as intuitive as they could be at first glance, but in keeping the dual
  212.      goals of ease of use AND flexibility, but the actual FCODE handler
  213.      (the routine called CHGFLD in FED-DEMO) can be "canned", or predone to
  214.      be incorporated into your program.
  215.  
  216.  
  217.                               FCODE Returns:
  218.  
  219.                              Enter   -    0
  220.               F1      -    1                 F8      -    8
  221.               F2      -    2                 F9      -    9
  222.               F3      -    3                F10      -   10
  223.               F4      -    4                PgUp     -   11
  224.            Up Arrow   -    5                PgDn     -   12
  225.            Dn Arrow   -    6              Ctrl-PgUp  -   13
  226.               F7      -    7              Ctrl-PgDn  -   14
  227.                              Escape  -    15
  228.  
  229.  
  230.           Note that not EVERY possible key is trapped or returned.  Most
  231.      notably, F5 and F6 are not trapped.   This is not because FED is lazy
  232.      or dumb, but simply to cut down on the number of FCODES you need to
  233.      handle (and handle whether your program uses or needs those codes or
  234.      not) and to leave 2 keys open for response to any standing ON KEY() key
  235.      traps your main program may need to have active at all times.
  236.  
  237.         I have used FED in several applications and more often than not, the
  238.      keys trapped as is, are MORE than enough to do the job.   If you look
  239.      at FED-DEMO you will see that it does quite a bit, in record paging,
  240.      abort and save keys, and still has 3 or 4 FCODEs unused. In the long
  241.      run, you should find that FED offers a suffient number of editting keys
  242.      and with the use of a pre-done CHGFLD routine, it should be easy to
  243.      handle the number of FCODES that it can return.
  244.  
  245.           The FCODEs returned, comply to the following rule: FCODE returns
  246.      function keys as the number in it's "name": F1 is 1, F2 is 2 etc.  The
  247.      top 4 Function keys and the bottom 4 are trapped.  F5 and F6 are
  248.      skipped, so the Up Arrow and Dn Arrow return those FCODEs and then
  249.      the bottom Function keys return their number.   Beyond that, the PgUp,
  250.      PgDn and Ctrl-PgUp and Ctrl-PgDn are at the end, FCODEs 11, 12, 13 and
  251.      14.  Finally, Enter is 0, and Escape is 15.
  252.  
  253.           Your distribution diskette or original archive should have a file
  254.      called CHGFLD.SUB that can be easily edited (add a few RETURN <label>'s
  255.      to it and paste it into your current code).  FED and CHGFLD together
  256.      should make text input and data entry applications very easy and
  257.      simple.  Throughout the demo, you can also note the integration of
  258.      different GIZLIB functions and how they complement FED.
  259.  
  260.  
  261.  
  262.  
  263.         VII.         Internal Handling, COMMON Parameters
  264.  
  265.          FED does a few things internally on its own and a few others you
  266.      control and change throughout the course of your program by resetting
  267.      the COMMON parameters.  If you are not familiar with SHARED parameters
  268.      you should refer to your QB manual.  These are not passed as formal
  269.      arguments inside the parentheses when the program is CALLed but are set
  270.      in your main program.
  271.  
  272.  
  273.        Using the value of FSIZ as the maximum length allowed, FED provides
  274.      hatching from the end of the actual text to that maximum length.
  275.      If a string is longer than FSIZ upon entry to FED, it is truncated to
  276.      the maximum length.
  277.      ( It is important to note that upon GETting a string from a random
  278.      file, QB pads the string with spaces from the end of the text for the
  279.      length of the FIELD.  That is, if you LSET "JOHN DOE" in a FIELD 15
  280.      characters long, after a GET, the name becomes "JOHN DOE       ".  If
  281.      you pass this as is to FED with a FSIZ of 15, no hatching will appear
  282.      because FED does not distinguish the spaces as blank text or
  283.      attempt to modify the string.  See STRIP in GIZLIB.)
  284.  
  285.      - FED also highlights the current text or data as well as providing
  286.      the hatching.  When the editing is completed, and one of the 15 FCODE
  287.      keys are hit to exit the field (actually FED is exitted, and control is
  288.      returned to you), the highlighting is turned off.  This color control
  289.      is handled thru the use of 2 sets of color codes: FG, BG and FGD and
  290.      BGD.  These must be assigned valid BASIC color codes in the course of
  291.      your main code.  At the start, FED uses the FGD, BGD (as in
  292.      ForeGround_Data, BackGround_Data) colors and upon exitting, redisplays
  293.      it in the FG, BG colors.  These only need to be set once.
  294.  
  295.      - Caps or uppercase input from the keyboard can be forced on the fly
  296.      (ie without a sepoarate call) via the UCASE switch.  Set UCASE to 1 or
  297.      non zero for caps, 0 for to allow either lower or upper case.
  298.  
  299.      - Numbers ONLY can be selected in the same manner with the switch
  300.      NUMS.  When this is set, only numberic input is allowed, so to allow
  301.      for a mixed string such as an address, NUMS should be OFF (nums=0).
  302.      Additionally, you can redefine allowable characters for different
  303.      entries via NUM$.  For example, in a phone number entry the characters
  304.      "()-" may be allowable beyond 0-9, but in a dollar based entry $ and
  305.      "." may be allowable.  So prior to the CALL for a phone entry NUM$
  306.      would be set to "1234567890()-", and "1234567890$." for the dollar
  307.      based entry.  This method of defining the entire string rather than
  308.      just the extra ()-$ or . characters was chosen to allow category type
  309.      entries too.  So, to force a category type chose from a set of 4
  310.      choices, a NUM$="1234" or NUM$="1458" with NUMS=1, allows the user to
  311.      choose a ONLY a character listed in NUM$.
  312.  
  313.  
  314.  
  315.      - If the text string upon exitting FED is different than it was at the
  316.      start of the CALL to fed, then EDT is set to non-zero.  This allows you
  317.      to test to see if field in a record has been altrered.  FED only sets
  318.      it to 1 never to 0.  Since FED is just handling the input for different
  319.      strings, it never knows when a set of fields equalling a full record is
  320.      completed.  The EDT is how FED tells yopu that something has indeed
  321.      been editted.
  322.      ( Using this flag, you can include code in the CHGFLD routine to flash
  323.      a message that an EDIT is in process, as is done in FED-DEMO.  It is
  324.      also useful in precluding certain functions if an edited record is not
  325.      saved.  An example of this is shown in FED-DEMO where paging is
  326.      disallowed if a record is edited and unsaved.
  327.  
  328.      -  The final COMMON parameter to cover is BLEEP, this is a switch to
  329.      indicate whether sound is to be on or off.  The sound is more of a
  330.      bleep than a beep.  If this switch is set on (non zero) it allows the
  331.      bleep sound effect to sound at various times:
  332.      - An attempt to cursor right when the string has reached FSIZ (maximum
  333.        length).
  334.      - An attempt to enter an invalid character (an alpha character when
  335.        nums is ON).
  336.      - When an inserted character will cause the text to exceed the maximum
  337.        length.
  338.      - Cursor left attempted left of first character position.
  339.      - If cursor right appends more than 1 successive blanks to the text.
  340.  
  341.        Regardless of the state of bleep, FED disregards any such illegal
  342.      activities.  BLEEP just adds an error sound to the process.  While the
  343.      error sound has it's uses, it is not recommended that it be on all the
  344.      time - there are time when it is inappropriate.  For instance, if you
  345.      allow 8 positions for a phone number as in xxx-xxxx, when the 8th
  346.      character (7th number) is entered, the BLEEP error signal would sound.
  347.      Since this is not REALLY an error, entries such as this should probably
  348.      have BLEEP set to 0.  There are several examples of this in FED.
  349.  
  350.         In summary, the COMMON switch (0 or 1) parameters are:
  351.      UCASE - Convert alpha input to Uppercase
  352.      NUMS - Allow (numeric) input only from NUM$
  353.      NUM$ - Character string of allowable input, if NUMS is not 0.
  354.      FGD, BGD - Foreground and Background colors to diplay the string in
  355.                 while thsat strinmg is undergoing editing via FED.
  356.      FG, BG - Colors FED restores the string to upon exiting the CALLed
  357.               sub-program.
  358.      EDT - Flag set by FED to show if text is changed.
  359.      BLEEP - Switch to turn on or off BLEEPER error signal.
  360.